package com.breaking.second.activity.pager.adapter;

import android.content.Context;
import android.view.View;

import com.breaking.second.databinding.ItemNewsDetailBinding;
import com.breaking.second.entity.NewsDetailEntity;
import com.bumptech.glide.Glide;

import java.util.List;

public class NewsDetailAdapter extends BaseAdapter<ItemNewsDetailBinding> {
    private final List<NewsDetailEntity> newsDetailEntities;
    private final long user_id;

    public NewsDetailAdapter(Context context, List<NewsDetailEntity> newsDetailEntities, long userId) {
        super(context);
        this.newsDetailEntities = newsDetailEntities;
        user_id = userId;
    }

    @Override
    public void onBindViewHolder(ItemNewsDetailBinding binding, int position) {
        super.onBindViewHolder(binding, position);
        NewsDetailEntity newsDetail = newsDetailEntities.get(position);
        if (newsDetail.getFromUserId().equals(String.valueOf(user_id))) {
            binding.llA.setVisibility(View.GONE);
            binding.llB.setVisibility(View.VISIBLE);

            binding.contentB.setText(newsDetail.getContent());
            binding.usernameB.setText(newsDetail.getUsername());
        } else {
            binding.contentA.setText(newsDetail.getContent());
            binding.usernameA.setText(newsDetail.getUsername());
        }
    }

    @Override
    public int getItemCount() {
        return newsDetailEntities.size();
    }
}


